/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaces;

import conexion.Operaciones;
import javax.swing.JOptionPane;

/**
 *
 * @author vikko
 */
public class PanelAltaCliente extends javax.swing.JPanel {
   

    /**
     * Creates new form PanelAltaCliente
     */
    public PanelAltaCliente() {
        initComponents();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        imagen = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tfield_claveCliente = new javax.swing.JTextField();
        btn_agregarCliente = new javax.swing.JButton();
        btn_cancelar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        tfield_NombreCliente = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        tfield_ApellidoCliente = new javax.swing.JTextField();
        tfield_CalleNumCliente = new javax.swing.JTextField();
        tfield_Colonia = new javax.swing.JTextField();
        tfield_Ciudad = new javax.swing.JTextField();
        tfield_CodPos = new javax.swing.JTextField();
        tfield_RFC = new javax.swing.JTextField();
        tfield_Telefono = new javax.swing.JTextField();
        tfield_email = new javax.swing.JTextField();
        ComboTipoCliente = new javax.swing.JComboBox();

        setMaximumSize(new java.awt.Dimension(800, 579));
        setMinimumSize(new java.awt.Dimension(800, 579));
        setPreferredSize(new java.awt.Dimension(800, 579));

        imagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/pc_banner2.png"))); // NOI18N

        jLabel1.setText("Ingresa la siguente información del cliente.");

        jLabel2.setText("Clave:");

        btn_agregarCliente.setText("Agregar");
        btn_agregarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_agregarClienteActionPerformed(evt);
            }
        });

        btn_cancelar.setText("Cancelar");
        btn_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelarActionPerformed(evt);
            }
        });

        jLabel3.setText("Nombre:");

        jLabel4.setText("Apellidos:");

        jLabel5.setText("Calle y numero:");

        jLabel6.setText("Colonia:");

        jLabel7.setText("Ciudad:");

        jLabel8.setText("Codigo postal:");

        jLabel9.setText("R.F.C.:");

        jLabel10.setText("Teléfono:");

        jLabel11.setText("e-mail:");

        jLabel12.setText("Tipo cliente:");

        ComboTipoCliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mayorista", "Minorista" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(imagen)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(btn_cancelar)
                .addGap(18, 18, 18)
                .addComponent(btn_agregarCliente)
                .addGap(74, 74, 74))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfield_claveCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
                            .addComponent(tfield_NombreCliente)
                            .addComponent(tfield_ApellidoCliente)
                            .addComponent(tfield_CalleNumCliente)
                            .addComponent(tfield_Colonia)
                            .addComponent(tfield_Ciudad))
                        .addGap(66, 66, 66)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addGap(42, 42, 42)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfield_email)
                            .addComponent(tfield_Telefono)
                            .addComponent(tfield_CodPos)
                            .addComponent(tfield_RFC)
                            .addComponent(ComboTipoCliente, 0, 158, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(imagen)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tfield_claveCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfield_CodPos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfield_NombreCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(tfield_RFC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tfield_ApellidoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(tfield_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfield_CalleNumCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel11)
                    .addComponent(tfield_Telefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfield_Colonia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel12)
                    .addComponent(ComboTipoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tfield_Ciudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_agregarCliente)
                    .addComponent(btn_cancelar))
                .addGap(30, 30, 30))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btn_agregarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_agregarClienteActionPerformed
        int clave_cliente= Integer.parseInt(tfield_claveCliente.getText());
        String Nombre=tfield_NombreCliente.getText();
        String Apellidos=tfield_ApellidoCliente.getText();
        String calle_num=tfield_CalleNumCliente.getText();
        String colonia=tfield_Colonia.getText();
        String ciudad=tfield_Ciudad.getText();
        int cod_postal= Integer.parseInt(tfield_CodPos.getText());
        String rfc=tfield_RFC.getText();
        String telefono=tfield_Telefono.getText();
        String email=tfield_email.getText();
        String tipocliente= ComboTipoCliente.getSelectedItem().toString();
        System.out.println("Clave:"+clave_cliente);
        System.out.println("Nombre:"+Nombre);
        System.out.println("Apellidos:"+Apellidos);
        System.out.println("Calle y numero:"+calle_num);
        System.out.println("Colonia:"+colonia);
        System.out.println("Ciudad:"+ciudad);
        System.out.println("Codigo postal:"+cod_postal);
        System.out.println("rfc:"+rfc);
        System.out.println("telefono:"+telefono);
        System.out.println("email:"+email);
        System.out.println("tipocliente:"+tipocliente);
        
        Operaciones opera= new Operaciones();
        
        int resConsulta=opera.altaCliente(clave_cliente,Nombre,Apellidos,calle_num,colonia,ciudad,cod_postal,rfc,telefono,email,tipocliente);
        if (resConsulta==1)  //Verificación de que el usuario no exista en la BD.
                JOptionPane.showMessageDialog(null, "El cliente \""+Nombre+"\" fue dado de alta exitosamente", "Cliente registrado", JOptionPane.INFORMATION_MESSAGE);
            else if (resConsulta==-1)
                 JOptionPane.showMessageDialog(null, "El cliente \""+Nombre+"\" ya existe, por favor revise los datos.", "Error en registro", JOptionPane.ERROR_MESSAGE);
        tfield_claveCliente.setText("");       
        tfield_NombreCliente.setText("");
               tfield_ApellidoCliente.setText("");
               tfield_CalleNumCliente.setText("");
               tfield_Colonia.setText("");
               tfield_Ciudad.setText("");
               tfield_CodPos.setText("");
               tfield_RFC.setText("");
               tfield_Telefono.setText("");
               tfield_email.setText("");
               
                 
           
    
    
        
    
        
        
        
        
        
        
    }//GEN-LAST:event_btn_agregarClienteActionPerformed

    private void btn_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelarActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btn_cancelarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ComboTipoCliente;
    private javax.swing.JButton btn_agregarCliente;
    private javax.swing.JButton btn_cancelar;
    private javax.swing.JLabel imagen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField tfield_ApellidoCliente;
    private javax.swing.JTextField tfield_CalleNumCliente;
    private javax.swing.JTextField tfield_Ciudad;
    private javax.swing.JTextField tfield_CodPos;
    private javax.swing.JTextField tfield_Colonia;
    private javax.swing.JTextField tfield_NombreCliente;
    private javax.swing.JTextField tfield_RFC;
    private javax.swing.JTextField tfield_Telefono;
    private javax.swing.JTextField tfield_claveCliente;
    private javax.swing.JTextField tfield_email;
    // End of variables declaration//GEN-END:variables
}
